package com.szd.qiongyou20.home.adapter;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridView;

import com.szd.qiongyou20.R;
import com.szd.qiongyou20.home.bean.CityData;

import java.util.List;

/**
 * Created by SZD on 2016/11/25.
 */

public class ViewPager_City_Special_Adapter extends PagerAdapter {

    private Context mContext;

    private List<CityData.DataBean.CityRecommendTagBean> mList;
    private LayoutInflater mInflater;

    public ViewPager_City_Special_Adapter(Context context, List<CityData.DataBean.CityRecommendTagBean> list) {
        mContext = context;
        mList = list;
        mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }


    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        View view = mInflater.inflate(R.layout.item_city_special_viewpager, null);
        GridView gridView = (GridView) view.findViewById(R.id.GridView_city_special);

        List<CityData.DataBean.CityRecommendTagBean.ListsBean> lists =
                mList.get(position).getLists();

        // 对GridView进行操作
        GridView_City_Special_Adapter gridView_city_special_adapter =
                new GridView_City_Special_Adapter(mContext, lists);

        gridView.setAdapter(gridView_city_special_adapter);

        container.addView(view);
        return view;
    }

//    @Override
//    public Object instantiateItem(View container, int position) {
//        ViewHolder holder = null;
//        if (container == null) {
//            container = mInflater.inflate(R.layout.item_city_special_viewpager, null);
//            holder = new ViewHolder(container);
//            container.setTag(holder);
//        } else {
//            holder = (ViewHolder) container.getTag();
//        }
//
//        List<CityData.DataBean.CityRecommendTagBean.ListsBean> lists =
//                mList.get(position).getLists();
//
//        GridView_City_Special_Adapter gridView_city_special_adapter =
//                new GridView_City_Special_Adapter(mContext, lists);
//
//        holder.mGridViewCitySpecial.setAdapter(gridView_city_special_adapter);
//        return container;
//    }

    @Override
    public CharSequence getPageTitle(int position) {
        return mList.get(position).getName();
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
//        super.destroyItem(container, position, object);
        container.removeView((View) object);
    }
}






